import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: () => import('@/views/Layout.vue'),
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/Home')
      },
      {
        path: '/category/:id',
        name: 'category',
        component: () => import('@/views/category/index.vue')
      },
      {
        path: '/category/sub/:id',
        name: 'categorySub',
        props: true,
        component: () => import('@/views/category/sub.vue')
      },
      {
        path: '/product/:id',
        name: 'product',
        props: true,
        component: () => import('@/views/goods/index.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
  // scrollBehavior () {
  //   return { top: 0, left: 0 }
  // }
})

router.afterEach((to, from) => {
  window.scrollTo(0, 0)
})

export default router
